﻿package plugin.npcDialog.ui.panels.ems
{
    import cmd.*;
    import com.core.*;
    import com.greensock.*;
    import com.sh.game.util.*;
    import manager.*;
    import morn.core.components.*;
    import morn.core.handlers.*;
    import morn.core.utils.*;
    import plugin.newvip.model.*;
    import pluginfw.*;
    import uiresource.npcdialogs.*;
    import view.message.*;

    public class NpcEMSPanel extends EmsRewardUI implements INpcDialogContent
    {
        private var lightIndex:int = 0;
        private var tweenMax:TweenMax;

        public function NpcEMSPanel()
        {
            return;
        }// end function

        public function show(param1:Object, param2:Object) : void
        {
            var _loc_8:int = 0;
            var _loc_9:int = 0;
            var _loc_3:* = ModelProxy.getValue("data", "ems");
            var _loc_4:* = ConfigDictionary.data.ems;
            var _loc_5:* = ConfigDictionary.data.ems[_loc_3[0]];
            var _loc_6:* = UserData.getUserData();
            var _loc_7:* = UserData.getUserData().level;
            _loc_8 = _loc_4[_loc_3[0]].rewardGold * Math.min(2, Math.max(1, int(_loc_7 / 20) - 3));
            _loc_9 = _loc_4[_loc_3[0]].rewardExp * (int(_loc_7 / 10) - 5);
            var _loc_10:Array = [];
            [].push({desc:StringUtil.substitute("(经验：{0}，金币：{1})", _loc_9, _loc_8), type:"单倍领取", tips:"1倍领取" + MColor.getHMTL("免费", 81)});
            this.lightIndex = 1;
            if (VipCheck.checkVip() > 0)
            {
                this.lightIndex = 2;
                if (VipCheck.checkVipLevel() > 2)
                {
                    this.lightIndex = 2;
                }
            }
            _loc_10.push({desc:StringUtil.substitute("(经验：{0}，金币：{1})", _loc_9 * 2, _loc_8 * 2), type:"多倍领取", tips:"2倍领取（VIP）" + MColor.getHMTL("VIP免费", 81)});
            _loc_10.push({desc:StringUtil.substitute("(经验：{0}，金币：{1})", _loc_9 * 3, _loc_8 * 3), type:"三倍领取", tips:"3倍领取（vip3以上）"});
            list.array = _loc_10;
            list.renderHandler = new Handler(this.listRender);
            return;
        }// end function

        private function listRender(param1:Component, param2:int) : void
        {
            var _loc_3:Object = null;
            var _loc_4:LinkButton = null;
            var _loc_5:Label = null;
            if (param2 < list.length)
            {
                _loc_3 = param1.dataSource;
                _loc_4 = param1.getChildByName("link_lq") as LinkButton;
                _loc_4.label = _loc_3.type;
                _loc_4.clickHandler = new Handler(this.mouseHandler, [param2]);
                _loc_4.toolTip = _loc_3.tips;
                _loc_5 = param1.getChildByName("txt_msg") as Label;
                _loc_5.text = _loc_3.desc;
                if (this.lightIndex >= param2)
                {
                    _loc_4.filters = [];
                }
                else
                {
                    ObjectUtils.gray(_loc_4);
                }
                if (this.lightIndex > 0)
                {
                    if (param2 == this.lightIndex)
                    {
                        if (this.tweenMax)
                        {
                            this.tweenMax.kill();
                            this.tweenMax = null;
                        }
                        this.tweenMax = TweenMax.to(_loc_4, 1, {glowFilter:{color:16763904, alpha:1, blurX:10, blurY:10}, yoyo:true, repeat:int.MAX_VALUE, alpha:1});
                    }
                }
            }
            return;
        }// end function

        private function mouseHandler(param1:int) : void
        {
            var type:* = param1;
            switch(type)
            {
                case 0:
                {
                    PluginManager.instance.sendToServer("ems", CMDEms.CompleteEms, 1);
                    break;
                }
                case 1:
                {
                    if (VipCheck.checkVip() != 0)
                    {
                        PluginManager.instance.sendToServer("ems", CMDEms.CompleteEms, 2);
                    }
                    else
                    {
                        WarningManager.show(141);
                    }
                    break;
                }
                case 2:
                {
                    if (VipCheck.checkVip() >= 0)
                    {
                        if (VipCheck.checkVipLevel() > 2)
                        {
                            Alert2.show("三倍领取奖励需要消耗500元宝", "", ["确定", "取消"], function (param1:int, param2:Object) : void
            {
                if (param1 == 0)
                {
                    PluginManager.instance.sendToServer("ems", CMDEms.CompleteEms, 3);
                }
                return;
            }// end function
            );
                        }
                        else
                        {
                            WarningManager.show(142);
                        }
                    }
                    else
                    {
                        WarningManager.show(141);
                    }
                    break;
                }
                default:
                {
                    break;
                }
            }
            return;
        }// end function

        public function close() : void
        {
            if (this.parent)
            {
                this.parent.removeChild(this);
            }
            return;
        }// end function

        public function update(param1:Object, param2:int = 0) : void
        {
            return;
        }// end function

    }
}
